﻿using System.Linq;
using SharePointUtilitiesForDevelopers.Repository;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace SharePointUtilitiesForDevelopers.Tests.Repository
{
    /// <summary>
    ///Test class for <see cref="SharePointListRepository"/>.
    ///</summary>
    [TestClass]
    public class SharePointListRepositoryTest
    {
        private const string siteUrl = "http://contoso.com";
        private const string listName = "{087BD6CB-9966-4257-B2E5-57458AC00728}";
        private const string viewName = "{46EBA9AB-A72F-4B66-BDF8-781B29AC42A2}";
        private const string query = "<Query><Where><Eq><FieldRef Name=\"FileLeafRef\" /><Value Type=\"File\" >Key.txt</Value></Eq></Where></Query>";
        private static readonly string viewFields = (new[] {"DocIcon", "LinkFilename"}).ToViewFieldsXElement().ToString();

        [TestInitialize]
        public void Initialize()
        {
            //TODO: mock gateway
        }

        [TestMethod]
        public void GetListItemsByListTest()
        {
            var target = ServiceLocator.Resolve<ISharePointListRepository>();
            var actual = target.GetListItems(siteUrl, listName, null, null, null, null, null, null);
            Assert.IsTrue(actual.Count() > 0);
        }

        [TestMethod]
        public void GetListItemsByListViewTest()
        {
            var target = ServiceLocator.Resolve<ISharePointListRepository>();
            var actual = target.GetListItems(siteUrl, listName, viewName, null, null, null, null, null);
            Assert.IsTrue(actual.Count() > 0);
        }

        [TestMethod]
        public void GetListItemsByQueryTest()
        {
            var target = ServiceLocator.Resolve<ISharePointListRepository>();
            var actual = target.GetListItems(siteUrl, listName, null, query, viewFields, null, null, null);
            Assert.AreEqual(1, actual.Count());
        }
    }
}